package com.evolution.timer;

import java.util.TimerTask;

import com.evolution.control.Controller;
import com.evolution.model.World;
import com.evolution.utils.RandomGenerator;

public class GrowFoodTask extends TimerTask {

	private Controller controller;
	
	public GrowFoodTask(Controller controller){
		this.controller = controller;
	}
	
	@Override
	public void run() {
		World world = controller.getWorld();
		for(int x = 0;x < world.WORLD_WIDTH;x++){
			for(int y = 0;y < world.WORLD_HEIGHT;y++){
				if(world.spaces[x][y].hasFood()){
					if(RandomGenerator.randomBoolean()){
						world.spaces[x][y].consumeFood();
					}
				}else{
					if(RandomGenerator.randomBoolean()){
						world.spaces[x][y].growFood();
					}
				}
			}
		}
		
		controller.worldChanged();
	}
}
